const dataName = 'GEEK_TOKEN'

// 设置当前选择的地址
export const setToken = (val) => {
  if (typeof val === 'object') {
    val = JSON.stringify(val)
  }
  localStorage.setItem(dataName, val)
}

// 读取当前选择的地址
export const getToken = () => {
  const data = localStorage.getItem(dataName) || {}
  try {
    return JSON.parse(data)
  } catch (err) {
    return data
  }
}

// 删除当前选择的地址
export const removeToken = () => localStorage.removeItem(dataName)

// 判断有没有当前选择的地址
export const hasToken = () => !!localStorage.getItem(dataName)
